/**
 * Copyright (c) 2012 Nokia Corporation. 
 */

package com.nokia.example.tictactoe;

import javax.microedition.lcdui.Display;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

import com.nokia.example.tictactoe.ui.MainView;
import com.nokia.mid.ui.VirtualKeyboard;

/**
 * The main class of the application.
 */
public class Main extends MIDlet {//implements CommandListener {	
	// Members
	private static Display _display = null;
	private Splash  _splash = null;
	private MainView _mainView = null;
	
	/**
	 * Constructor.
	 */
	public Main() {
		_display = Display.getDisplay(this);
		_splash = new Splash(0xFFFFFF);
		
		// Hide the command for opening the virtual keypad
        try {
            Class.forName("com.nokia.mid.ui.VirtualKeyboard");
            VirtualKeyboard.hideOpenKeypadCommand(true);
        }
        catch (ClassNotFoundException e) {}		
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.microedition.midlet.MIDlet#startApp()
	 */
	protected void startApp() throws MIDletStateChangeException {
		_mainView = new MainView(this);
		final int height = _mainView.getHeight();
		
		if (height > 320) {
			_splash.loadImage("/splash_240x400.png");
		}
		else {
			_splash.loadImage("/splash_240x320.png");
		}
		
		_splash.show(_display, _mainView, 3000);
		_mainView.init();
	}
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.microedition.midlet.MIDlet#destroyApp(boolean)
	 */
	protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.microedition.midlet.MIDlet#pauseApp()
	 */
	protected void pauseApp() {
	}

	/**
	 * Quits the application.
	 */
	public void quit() {
		notifyDestroyed();
	}
}
